class Solution
{
public:
    bool checkInclusion(string s1, string s2)
    {
        int n1 = s1.size();
        int n2 = s2.size();
        if (n1 > n2)
        {
            return false;
        }
        vector<int> charCount1(26, 0);
        vector<int> charCount2(26, 0);
        for (auto c : s1)
        {
            ++charCount1[c - 'a'];
        }
        for (int i = 0; i < n1; ++i)
        {
            ++charCount2[s2[i] - 'a'];
        }
        if (charCount1 == charCount2)
        {
            return true;
        }
        for (int i = n1; i < n2; ++i)
        {
            ++charCount2[s2[i] - 'a'];
            --charCount2[s2[i - n1] - 'a'];
            if (charCount1 == charCount2)
            {
                return true;
            }
        }
        return false;
    }
};